

package cn.shengchao.examstar.me.course.ohs.remote.mq;

import cn.shengchao.base.event.PayRefundMessageEvent;
import cn.shengchao.examstar.me.course.ohs.local.appervices.MyCourseAppService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class OrderPayRefundEventListener {
    @Autowired
    private MyCourseAppService myCourseAppService;

    @EventListener
    public void handleCustomEvent(PayRefundMessageEvent event) {
        JSONObject order = JSON.parseObject(JSON.toJSONString(event.getSource()));
        //用户id
        Long userId = order.getLong("userId");
        //产品id
        Long productId = order.getLong("productId");
        //订单号
        Long orderId = order.getLong("orderId");
        JSONArray productItemId = order.getJSONArray("orderItemIds");
        log.info("产品处理，收到订单:{},退款完成事件,用户:{},产品:{},子产品:{}", orderId, userId, productId, productItemId);
        myCourseAppService.removeCourse(userId, productId, productItemId.toJavaList(Long.class));
    }
}
